package com.xysq.activity;

import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.TextView;

import com.xysq.lemon.R;
import com.xysq.util.ToastUtil;

import butterknife.InjectView;

public class WriteDescriptionActivity extends BaseActivity implements View.OnClickListener{

    @InjectView(R.id.edit_write_description)
    EditText writeDescriptionEdit;
    @InjectView(R.id.txt_save)
    TextView saveTxt;
    @InjectView(R.id.ibtn_back)
    ImageButton backIbtn;
    String extraDescription;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_write_description);
        getExtra();
        initView();

    }

    private void getExtra() {
        Intent intent = getIntent();
        extraDescription = intent.getStringExtra("description");
        writeDescriptionEdit.setText(intent.getStringExtra("description"));
    }

    private void initView() {
        saveTxt.setOnClickListener(this);
        backIbtn.setOnClickListener(this);
    }

    @Override
    public void onClick(View view) {
        if(view == saveTxt){
            if(writeDescriptionEdit.getText().toString().trim().length() != 0) {
                Intent intent = new Intent();
                intent.putExtra("description", writeDescriptionEdit.getText().toString());
                setResult(PublishGoodsActivity.GET_DESCRIPTION, intent);
                ToastUtil.showShort(WriteDescriptionActivity.this, "商品描述保存成功！");
                finish();
            }else {
                ToastUtil.showShort(WriteDescriptionActivity.this, "描述不能为空");
            }
        }
        if(view == backIbtn){
            Intent intent = new Intent();
            if(!TextUtils.isEmpty(extraDescription)) {
                intent.putExtra("description", extraDescription);
            }else {
                intent.putExtra("description", "");
            }
            setResult(PublishGoodsActivity.GET_DESCRIPTION, intent);
            finish();
        }
    }
}
